package com.hl.implic
import java.io.File

import scala.io.Source

/**
  * Created by yuanhailong on 2021/10/10.
  */
class RichFile(val f:File) {
  def read(): String = Source.fromFile(f).mkString
}


//用一个对象，装载我的隐式转换
object MyPredef{
  //导入隐式转换
  implicit def fileWarper(f:File)=new RichFile(f)
}


object RichFile{



  def main(args: Array[String]): Unit = {

    val f=new File("D://yinew.log")


    //显示增强
    //val contexts=new RichFile(f).read();

    //隐式增强：read方法在File里面没有，
    import MyPredef.fileWarper
    val contents=f.read()

    println(contents)

  }
}


